package com.hd123.rumba.runtime;

import java.util.Date;

import com.hd123.rumba.request.JspLib;
import com.hd123.rumba.runtime.FormatSettings;

/**
 * 非持久化的. 保存在Vector RunOnce.processes中, 由RunOnce来管理.
 * @author caili
 * @see #RunOnce
 */
public class RunOnceInfo {
  String userId; // set by trigger
  String processId; // set by trigger
  Thread thread; // set by trigger
  Date startTime; // set by this class
  Date lastUpdated; // set by this class
  Date endTime; // set by worker
  int percentage; // set by worker
  int state; // set by worker
  StringBuffer info=new StringBuffer(); // set by worker
  Object result; // set by worker

  public static final int STATE_ERROR = -1;
  public static final int STATE_RUNNING = 0;
  public static final int STATE_SUCC = 1;
  public static final int STATE_WARNING = 2;

  public Date getEndTime() {
    return endTime;
  }

  public void setEndTime(Date endTime) {
    this.endTime = endTime;
  }



  public StringBuffer getInfo() {
    return info;
  }

  public void setInfo(StringBuffer info) {
    this.info = info;
  }

  public Date getLastUpdated() {
    return lastUpdated;
  }

  public void setLastUpdated(Date lastUpdated) {
    this.lastUpdated = lastUpdated;
  }

  public int getPercentage() {
    return percentage;
  }

  public void setPercentage(int percentage) {
    this.percentage = percentage;
  }

  public String getProcessId() {
    return processId;
  }

  public void setProcessId(String processId) {
    this.processId = processId;
  }

  public Date getStartTime() {
    return startTime;
  }

  public void setStartTime(Date startTime) {
    this.startTime = startTime;
  }

  public int getState() {
    return state;
  }

  public void setState(int state) {
    this.state = state;
  }

  public Thread getThread() {
    return thread;
  }

  public void setThread(Thread thread) {
    this.thread = thread;
  }

  public String getUserId() {
    return userId;
  }

  public void setUserId(String userId) {
    this.userId = userId;
  }
  
  public Object getResult() {
    return result;
  }

  public void setResult(Object result) {
    this.result = result;
  }

  public String debugInfo() {
    StringBuffer sb = new StringBuffer(10);
    sb.append("userId=" + getUserId() + ",");
    sb.append("processId=" + getProcessId() + ",");
    sb.append("startTime=" + JspLib.format(getStartTime(), FormatSettings.SDFyMdHms) + ",");
    sb.append("lastUpdated=" + JspLib.format(getLastUpdated(), FormatSettings.SDFyMdHms) + ",");
    sb.append("endTime=" + JspLib.format(getEndTime(), FormatSettings.SDFyMdHms) + ",");
    sb.append("percentage=" + getPercentage() + ",");
    sb.append("state=" + getState() + ",");
    sb.append("info=" + getInfo().toString());
    return sb.toString();
  }
}
